﻿using Newtonsoft.Json;
using SimpleTCP;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VswService_V7.Config;

namespace VswService_V7.Print
{

    //PH01 - BC1 BC2 SC3
    //PH02 - OS1
    //PH03 - BC4 BC5
    //PH04 - SC5
    //PH05 - SC1 SC2 SC4
    public class PrintClient
    {

        private static PrintClient _printClient;
        public static PrintClient PrintClientHelper
        {
            get
            {
                if (_printClient == null)
                {
                    _printClient = new PrintClient();
                }
                return _printClient;
            }
        }

        PrintClientSetting _printClientSetting;
        public PrintClient()
        {
            
        }



        public void SetPrintConfig(PrintClientSetting clientSetting)
        {
            _printClientSetting = clientSetting;
        }

        public void PrintBundle(string position,List<string> pipeList)
        {
            switch(position)
            {
                case "BC1":
                    {
                        using (SimpleTcpClient simple = new SimpleTcpClient().Connect(_printClientSetting.PrintServerIP, _printClientSetting.PrintServerPort))
                        {
                            PrintParameter para = GetPrintParameter(pipeList);
                            para.PRINTER = _printClientSetting.PH01;

                            string jstring = JsonConvert.SerializeObject(para);
                            simple.WriteLine("SET" + jstring);
                            simple.WriteLine("PRINT" + jstring);
                        }
                        break;
                    }

                case "BC2":
                    {
                        using (SimpleTcpClient simple = new SimpleTcpClient().Connect(_printClientSetting.PrintServerIP, _printClientSetting.PrintServerPort))
                        {
                            PrintParameter para = GetPrintParameter(pipeList);
                            para.PRINTER = _printClientSetting.PH01;

                            string jstring = JsonConvert.SerializeObject(para);
                            simple.WriteLine("SET" + jstring);
                            simple.WriteLine("PRINT" + jstring);
                        }
                        break;
                    }

                case "BC4":
                    {
                        using (SimpleTcpClient simple = new SimpleTcpClient().Connect(_printClientSetting.PrintServerIP, _printClientSetting.PrintServerPort))
                        {
                            PrintParameter para = GetPrintParameter(pipeList);
                            para.PRINTER = _printClientSetting.PH03;

                            string jstring = JsonConvert.SerializeObject(para);
                            simple.WriteLine("SET" + jstring);
                            simple.WriteLine("PRINT" + jstring);
                        }
                        break;
                    }

                case "BC5":
                    {
                        using (SimpleTcpClient simple = new SimpleTcpClient().Connect(_printClientSetting.PrintServerIP, _printClientSetting.PrintServerPort))
                        {
                            PrintParameter para = GetPrintParameter(pipeList);
                            para.PRINTER = _printClientSetting.PH03;

                            string jstring = JsonConvert.SerializeObject(para);
                            simple.WriteLine("SET" + jstring);
                            simple.WriteLine("PRINT" + jstring);
                        }
                        break;
                    }

                case "SC1":
                    {
                        using (SimpleTcpClient simple = new SimpleTcpClient().Connect(_printClientSetting.PrintServerIP, _printClientSetting.PrintServerPort))
                        {
                            PrintParameter para = GetPrintParameter(pipeList);
                            para.PRINTER = _printClientSetting.PH05;

                            string jstring = JsonConvert.SerializeObject(para);
                            simple.WriteLine("SET" + jstring);
                            simple.WriteLine("PRINT" + jstring);
                        }
                        break;
                    }

                case "SC2":
                    {
                        using (SimpleTcpClient simple = new SimpleTcpClient().Connect(_printClientSetting.PrintServerIP, _printClientSetting.PrintServerPort))
                        {
                            PrintParameter para = GetPrintParameter(pipeList);
                            para.PRINTER = _printClientSetting.PH05;

                            string jstring = JsonConvert.SerializeObject(para);
                            simple.WriteLine("SET" + jstring);
                            simple.WriteLine("PRINT" + jstring);
                        }
                        break;
                    }

                case "SC3":
                    {
                        using (SimpleTcpClient simple = new SimpleTcpClient().Connect(_printClientSetting.PrintServerIP, _printClientSetting.PrintServerPort))
                        {
                            PrintParameter para = GetPrintParameter(pipeList);
                            para.PRINTER = _printClientSetting.PH01;

                            string jstring = JsonConvert.SerializeObject(para);
                            simple.WriteLine("SET" + jstring);
                            simple.WriteLine("PRINT" + jstring);
                        }
                        break;
                    }

                case "SC4":
                    {
                        using (SimpleTcpClient simple = new SimpleTcpClient().Connect(_printClientSetting.PrintServerIP, _printClientSetting.PrintServerPort))
                        {
                            PrintParameter para = GetPrintParameter(pipeList);
                            para.PRINTER = _printClientSetting.PH05;

                            string jstring = JsonConvert.SerializeObject(para);
                            simple.WriteLine("SET" + jstring);
                            simple.WriteLine("PRINT" + jstring);
                        }
                        break;
                    }

                case "SC5":
                    {
                        using (SimpleTcpClient simple = new SimpleTcpClient().Connect(_printClientSetting.PrintServerIP, _printClientSetting.PrintServerPort))
                        {
                            PrintParameter para = GetPrintParameter(pipeList);
                            para.PRINTER = _printClientSetting.PH04;
                            string jstring = JsonConvert.SerializeObject(para);
                            simple.WriteLine("SET" + jstring);
                            simple.WriteLine("PRINT" + jstring);
                        }
                        break;
                    }
            }
        }

        private PrintParameter GetPrintParameter(List<string> pipeList)
        {
            PrintParameter printParameter = new PrintParameter();

            return printParameter;
        }


    }


    public class PrintParameter
    {
        public string TEMPLATE_FILE { get; set; }

        public string PRINTER { get; set; }
    }


}
